﻿using System;
using System.Collections.Generic;
using System.Text;
using Ebada.Platform.Model;
using Ebada.Core;

namespace Ebada.Modules.Document {
    /// <summary>
    /// 
    /// </summary>
    public static class DocumentHelper {
        /// <summary>
        /// 创建单证
        /// </summary>
        /// <param name="orgid">责任单位编号</param>
        /// <param name="orgname">责任单位名称</param>
        /// <param name="businessCode">业务单号</param>
        /// <param name="act_code">关联作业代码</param>
        /// <param name="act_name">关联作业名称</param>
        /// <param name="act_date">作业时间</param>
        /// <param name="org_id">关联单位标识(承运商)（可以为空）</param>
        /// <returns></returns>
        public static IList<Documents> CreateDocuments(string orgid, string orgname, string businessCode, string act_code, string act_name, DateTime act_date, string org_id) {
            List<Documents> list = new List<Documents>();
            IList<DocumentType> typelist = Client.ClientHelper.PlatformSqlMap.GetList<DocumentType>(" where Act_Code='" + act_code + "'");
            foreach (DocumentType type in typelist) {
                Documents doc = new Documents();
                doc.DocumentID = doc.CreateID();
                doc.DocumentTypeID = type.DocumentTypeID;
                doc.DocumentTypeName = type.DocTypeName;
                doc.DocState = 0;
                doc.DocStateName = "未提交";
                doc.DocCode = doc.CreateID();
                doc.BusinessCode = businessCode;
                doc.Act_Code = act_code;
                doc.Act_Name = act_name;
                doc.Act_Date = act_date;
                doc.SubmitDateLimit = act_date.Date.AddDays((int)type.SubmitDate);
                doc.ValidityDate = act_date.Date.AddDays((int)type.ValidityDate);
                doc.RemindDate = doc.ValidityDate.AddDays(-(int)type.SubmitDate);
                doc.Org_ID = org_id;
                list.Add(doc);
            }
            if (list.Count > 0)
                Client.ClientHelper.PlatformSqlMap.ExecuteTransationUpdate(list, null, null);
            return list;
        }

    }
}
